/*** Class Name: iFulfillBatchJobTest
 * Author: Accenture
 * Date: 19-July-2011
 * Requirement/Project Name: iFulfill
 * Requirement Description: Test class for fulfullFulfillmentItemEmailHandlerTest
 **/

@istest
private  class IfulfullFulfillmentItemEmailHandlerTest 
{
  /**
  *  Test method 
  */
  static testMethod void testBatch() 
  {
       Messaging.InboundEmail email = new Messaging.InboundEmail() ;
       Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
       email.subject = 'Fulfillment Item name-FI-000000035';
       env.fromAddress = 'user@acme.com';
       Fullfilment_Item__c FI = new Fullfilment_Item__c(   Main_Listing_Phone_Number__c = '100',Listed_Name__c ='XYZ',Heading_Name__c ='Heading name',Item_Id__c = 'Item id' ,Product_Code__c ='p1',UDAC__c ='Udac1',Region__c = 'region1',Transaction_Type__c ='New');
       insert FI;
       // Call the class and test it with the data in the test method.
       IfulfullFulfillmentItemEmailHandler  fiEmailHandler = new IfulfullFulfillmentItemEmailHandler();
       fiEmailHandler .handleInboundEmail(email, env );
       email.subject = 'Fulfillment Item name-';
       email.plainTextBody = 'For system use only, DO NOT DELETE Fulfillment - FI-000000035 ';
       
            // add an attachment
      Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
      attachment.body = blob.valueOf('my attachment text');
      attachment.fileName = 'textfile.txt';
      attachment.mimeTypeSubType = 'text/plain';
 
      email.binaryAttachments = new Messaging.inboundEmail.BinaryAttachment[] { attachment };
     
      Messaging.InboundEmail.TextAttachment textAttachment = new Messaging.InboundEmail.TextAttachment();
      textAttachment .body ='my attachment text';
      textAttachment .fileName = 'textfile.txt';
      textAttachment .mimeTypeSubType = 'text/plain';
 
      email.textAttachments= new Messaging.inboundEmail.TextAttachment[] { textAttachment };
 
       
       fiEmailHandler.handleInboundEmail(email, env ); 
       
       list<Fullfilment_Item__c> fiList = [Select name from Fullfilment_Item__c where ID = :FI.id];
       if(fiList.size() > 0)
       {
           email.subject = 'Fulfillment Item name-';
           email.plainTextBody = 'For system use only, DO NOT DELETE Fulfillment -' + fiList.get(0).name;
           fiEmailHandler.handleInboundEmail(email, env ); 
    
       }
    }
}